//
//  ViewController.m
//  DemoAdView
//
//  Created by 唐可雄 on 16/6/15.
//  Copyright © 2016年 swustyc. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<YCAdViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    self.adView.intervalForTimer = 2;
//    self.adView.infiniteLoopEnable = YES;
    self.adView.delegate = self;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self.adView startTimer];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    
    [self.adView stopTimer];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - YCAdViewDelegate

- (NSUInteger)numberOfItemsInAdView:(YCAdView *)adView {
    return 2;
}

- (UIColor *)colorForIndex:(NSInteger)index {
    if (index == 0) {
        return [UIColor redColor];
    } else if (index == 1) {
        return [UIColor greenColor];
    } else if (index == 2) {
        return [UIColor blueColor];
    } else if (index == 3) {
        return [UIColor purpleColor];
    } else if (index == 4) {
        return [UIColor blackColor];
    }
    
    return nil;
}

- (void)adView:(YCAdView *)adView configItemView:(UIImageView *)imgView atIndex:(NSInteger)index {
    UIColor *color = [self colorForIndex:index];
    
    imgView.backgroundColor = color;
}

- (void)adViewWillNextLoop:(YCAdView *)adView {
    if ([self.navigationController.topViewController isKindOfClass:[ViewController class]]) {
        [self performSegueWithIdentifier:@"segueShow" sender:nil];
    }
}

- (void)adViewWillLastLoop:(YCAdView *)adView {
    
}

- (void)adView:(YCAdView *)adView didClickAtIndex:(NSInteger)index {
    NSLog(@"sss");
}

@end
